package ControlLayer;

import java.util.ArrayList;
import ModelLayer.*;

/**
 * Controller class for the address book
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class AddressCtr
{
    
    private static AddressBook addressBook;
    private static long personIDCount = 0;
    
    /**
     * Contructor for obect of this class.
     */
    public AddressCtr()
    {
        addressBook = AddressBook.getInstance();
    }
    
    
    /**
     * This method search the containter for and returns an object of type Person identified by given id.
     * 
     * @param   id      The id of  the person to be found.
     * 
     * @return  The person identified by the given id, as a Person. If none found null wil be returned.
     */
    public Person getPerson(long id)
    {
        return addressBook.getPerson(id);
    }
    
    
    /**
     * This method adds a person with the given details to the container.
     * 
     * @param   id          The id that is to identify the person to be created. A long.
     * @param   firstName   The first name of the person to be created. A String.
     * @param   surname     The last name of the person to be created. A String.
     * @param   address     The address of the person to be created. A String.
     * @param   postalCode  The zip code of the person to be created. A String.
     * @param   city        The town of the person to be created. A String.
     * @param   phone       The phone number of the person to be created. A String.
     */
    public void createPerson(String firstName, String surname, String address, String postalCode, String city, String phone)
    {   
        personIDCount++;
        addressBook.createPerson(personIDCount, firstName, surname, address, postalCode, city, phone);
    }
    
    /**
     * This method deletes a person with the given id from the container.
     * 
     * @param   id  The id of the person to be deleted. A long.
     */
    public boolean deletePerson(long id)
    {
        return addressBook.deletePerson(id);
    }
    
    /**
     * This method updates all the information of the first person found indetified by the given id.
     * 
     * @param   id          The id that identifies the person to be updated. A long.
     * @param   firstName   The new first name of the person. A String.
     * @param   surname     The new last name of the person. A String.
     * @param   address     The new address of the person. A String.
     * @param   zipCode     The new zip code of the person. A String.
     * @param   town        The new town of the person. A String.
     * @param   phone       The new phone number of the person. A String.
     */
    public boolean updatePerson(long id, String firstName, String surname, String address, String zipCode, String town, String phone)
    {
        return addressBook.updatePerson(id, firstName, surname, address, zipCode, town, phone);
    }
    
    /**
     * This method returns a list of all the persons in the container.
     * 
     * @return  A list of person, as an ArrayList<Person>.
     */
    public ArrayList listAllPersons()
    {
          return addressBook.listAllPersons();
    }
}
